#include <iostream>
#include "log/log.h"



void TestLog()
{
    std::cout << "--------------------------" << std::endl;
    log_trace("This is a trace");
    log_debug("This is a debug");
    log_info("This is a info");
    log_warn("This is a warn");
    log_error("This is a error");
    log_fatal("This is a fatal");
}
pthread_mutex_t mutex_log;

void log_lock(bool lock, void* udata)
{
    pthread_mutex_t* LOCK = (pthread_mutex_t*)(udata);
    if (lock)
        pthread_mutex_lock(LOCK);
    else
        pthread_mutex_unlock(LOCK);
}

void callback(log_Event *ev)
{
    printf("{%s}\n", (char*)ev->udata);
}

int main()
{
    log_set_level(2);
    printf("------[%s]------\n", log_level_string(2));
    log_set_quiet(0);

    pthread_mutex_init(&mutex_log, NULL);
    log_set_lock(log_lock, &mutex_log);
    log_add_callback(callback, (void*)"xxRR", 4);

    FILE* fd = fopen("log.txt", "w");
    log_add_fp(fd, 2);

    getchar();
    TestLog();
    getchar();
    TestLog();

    fclose(fd);
    return 0;
}